#include <criterion/criterion.h>
#include "ringQueue.h"

// int main(int argc, char const *argv[])
// {
//     Queue *q;
//     int a = 1;
//     int b = 3;
//     int c = 10;
//     q = getInitQueue();
//     Item aI = initItem(&a, sizeof(a));
//     Item bI = initItem(&b, sizeof(b));
//     Item cI = initItem(&c, sizeof(c));

//     enQueue(q, aI);
//     enQueue(q, bI);
//     enQueue(q, cI);

//     DestroyQueue(q);
//     sleep(20000);
// }

Test(ringQueue, enQueue_and_deQueue)
{
    cr_skip_test();
    Queue *q;
    int a = 1;
    int b = 3;
    int c = 10;
    q = getInitQueue();
    Item aI = initItem(&a, sizeof(a));
    Item bI = initItem(&b, sizeof(b));
    Item cI = initItem(&c, sizeof(c));

    enQueue(q, aI);
    enQueue(q, bI);
    enQueue(q, cI);

    int first = *(int *)q->item->data;
    int second = *(int *)q->next->item->data;
    int third = *(int *)q->next->next->item->data;
    cr_assert_eq(QueueLength(q), 3);
    cr_assert_eq(first, a);
    cr_assert_eq(second, b);
    cr_assert_eq(third, c);
    cr_assert_neq(q->next->next->next, NULL);
    cr_assert_eq(q->next->next->next->item, NULL);

    Queue *tail = deQueue(q);
    cr_assert_eq(QueueLength(q), 2);
    cr_assert_eq(tail->item->size, sizeof(int));
    cr_assert_eq(*(int *)((Item)tail->item->data), c);

    Queue *tail2 = deQueue(q);
    cr_assert_eq(QueueLength(q), 1);
    cr_assert_eq(tail2->item->size, sizeof(int));
    cr_assert_eq(*(int *)((Item)tail2->item->data), b);

    Queue *tail3 = deQueue(q);
    cr_assert_eq(QueueLength(q), 0);
    cr_assert_eq(tail3->item->size, sizeof(int));
    cr_assert_eq(*(int *)((Item)tail3->item->data), a);
}

Test(ringQueue, destroyQueue_and_isEmpty)
{
    cr_skip_test();
    Queue *q;
    int a = 1;
    int b = 3;
    int c = 10;
    q = getInitQueue();
    cr_assert_eq(IsEmpty(*q), true);
    Item aI = initItem(&a, sizeof(a));
    Item bI = initItem(&b, sizeof(b));
    Item cI = initItem(&c, sizeof(c));

    enQueue(q, aI);
    enQueue(q, bI);
    enQueue(q, cI);

    DestroyQueue(q);
    cr_assert_eq(QueueLength(q), 0);
}
